package com.estar.integaration.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estar.integaration.Mapper.ProductionScheduleMapper;
import com.estar.integaration.Service.IProductionScheduleService;
import com.estar.integaration.entity.ProductionSchedule;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YJL
 * @since 2021-11-18
 */
@Service
public class ProductionScheduleServiceImpl extends ServiceImpl<ProductionScheduleMapper, ProductionSchedule> implements IProductionScheduleService {

  @Autowired
  ProductionScheduleMapper productionScheduleMapper;

  /**
   * 根据id删除排期记录
   * @param id  生产id
   * @Author HLF
   */
  @Override
  public void deleteProductionScheduleById(String id) {
    QueryWrapper queryWrapper = new QueryWrapper();
    queryWrapper.eq("id",id);
    productionScheduleMapper.delete(queryWrapper);
  }

  /**
   * 功能： 筛选出所有的历史
   * @return
   */
  @Override
  public List<ProductionSchedule> selectAllPs() {
    List<ProductionSchedule> psList = productionScheduleMapper.selectList(null);
    return  psList;
  }

  @Override
  public HashMap<String, Date> getScheduleHash() {

    List<ProductionSchedule> productionScheduleList = productionScheduleMapper.selectList(null);

    HashMap<String,Date> AcodeScheduleHashMap = new HashMap<>();

    productionScheduleList.forEach(p -> AcodeScheduleHashMap.put(p.getACode(),p.getStandardComeTime()));

    return AcodeScheduleHashMap;

  }

}
